package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.system.CategoryBrandDto;
import com.atguigu.spzx.model.entity.system.Brand;
import com.atguigu.spzx.model.entity.system.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/product")
@Tag(name = "分类品牌管理")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService;
     @GetMapping("/findBrandByCategoryId/{categoryId}")
     @Operation(summary = "通过分类id获取品牌列表")
    public Result findBrandCategoryId(@PathVariable Long categoryId ){
         List<Brand> brandList = categoryBrandService.findBrandCategoryId(categoryId);
         return Result.OK(brandList);
     }
    @GetMapping("{page}/{limit}")
    @Operation(summary = "分页")
    public Result<PageInfo<CategoryBrand>> findByPage (@PathVariable Integer page, @PathVariable Integer limit,CategoryBrandDto categoryBrandDto){
         PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page,limit, categoryBrandDto);
         return Result.OK(pageInfo);
    }

    @PostMapping("/save")
    @Operation(summary = "添加品牌分类")
    public Result save (@RequestBody CategoryBrand categoryBrand){
         categoryBrandService.save(categoryBrand);
         return Result.OK();
    }

    @PutMapping("udateById")
    @Operation(summary = "根据id修改品牌")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
         categoryBrandService.updateById(categoryBrand);
         return Result.OK();
    }

    @DeleteMapping("/delById/{id}")
    @Operation(summary = "根据id删除品牌分类")
    public Result delById(@PathVariable Long id){
         categoryBrandService.delById(id);
         return Result.OK();
    }
}
